<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>收货地址</title>
  <link rel="stylesheet" href="../member/css/index.css">
  <link rel="stylesheet" href="../member/css/layui-v2.9.14.css">
  <style media="screen">
    * {
      font-family: "微软雅黑";
    }
  </style>
</head>

<body>
  <div id="nav">
    <nav>
     
      <div class="myjd">
        <h3>我的TMesh商城</h3>
        <button onclick="location.href='http://tmesh.cn'">返回TMesh商城首页</button>
      </div>
      <ul class="nav_ul">
        <li style="font-size: 15px"><a href='http://tmesh.cn'>首页</a></li>
        <li class="li hover" style="font-size: 15px">账户设置<i class="ul_i"></i>
            <ol>
                <li><a href="http://member.tmesh.cn/memberInfo.html">个人信息</a></li>
                <li><a href="javaScript:void(0);">账户安全</a></li>
                <li><a href="javaScript:void(0);">我的尺码</a></li>
                <li><a href="javaScript:void(0);">账号绑定</a></li>
                <li><a href="http://member.tmesh.cn/addressInfo.html">收货地址</a></li>
                <li><a href="javaScript:void(0);">用药人信息</a></li>
                <li><a href="javaScript:void(0);">分享绑定</a></li>
                <li><a href="javaScript:void(0);">邮件订阅</a></li>
                <li><a href="javaScript:void(0);">应用授权</a></li>
                <li><a href="javaScript:void(0);">快捷支付</a></li>
                <li><a href="javaScript:void(0);">增票资质</a></li>
                <li><a href="javaScript:void(0);">企业发票</a></li>
                <li><a href="javaScript:void(0);">采购需求单</a></li>
            </ol>
        </li>
        <li class="li" style="font-size: 15px">社区<i class="ul_i"></i>
          <ol>
              <li><a href="javaScript:void(0);">个人主页</a></li>
              <li><a href="javaScript:void(0);">我的活动</a></li>
              <li><a href="javaScript:void(0);">我的圈子</a></li>
              <li><a href="javaScript:void(0);">我的帖子</a></li>
          </ol>
        </li>
        <li style="font-size: 15px">消息</li>
      </ul>
      <div class="right">
        <div class="btn">
          <input type="text" placeholder="空调"><button>搜索</button>
        </div>
        <ul class="shop">
            <li><i class="shop_che"></i><a href="http://cart.tmesh.cn/cart.html">我的购物车 ></a>
            <ol>
              <li>
                <img src="../member/img/shop.png" alt="">
                <div>购物车中还没有商品，赶紧选购吧</div>
                <div style="clear:both;"></div>
              </li>
            </ol>
          </li>
        </ul>
      </div>
      <div style="clear:both;"></div>
    </nav>

  </div>
  <div style="clear:both;"></div>
  <div id="big">
    <div id="bigLeft">
      <ul>
        <h5>设置</h5>
        <li><a href="http://member.tmesh.cn/memberInfo.html">个人信息</a></li>
        <li><a style="color:#E4393C;font-weight:800;" href="http://member.tmesh.cn/addressInfo.html">收货地址</a></li>
      </ul>
      <ul>
        <h5>订单中心</h5>
        <li><a href="http://member.tmesh.cn/memberOrder.html">我的订单</a></li>
        <li>我的活动</li>
        <li>评价晒单</li>
        <li>我的常购商品<img src="../member/img/new.png"></li>
        <li>购物助手</li>
      </ul>
      <ul>
        <h5>关注中心</h5>
        <li>关注的商品</li>
        <li>关注的店铺</li>
        <li>关注的专辑</li>
        <li>收藏的内容<img src="../member/img/new.png"></li>
        <li>关注的活动</li>
        <li>浏览历史</li>
      </ul>
      <ul>
        <h5>资产中心</h5>
        <li>小金库</li>
        <li>TMesh商城白条</li>
        <li>领货码</li>
        <li>余额</li>
        <li>优惠券</li>
        <li>礼品卡</li>
        <li>京豆</li>
        <li>TMesh商城钢镚<img src="../member/img/new.png"></li>
      </ul>
      <ul>
        <h5>特色业务</h5>
        <li>我的营业厅</li>
        <li>TMesh商城通信</li>
        <li>定期购</li>
        <li>我的回收单</li>
        <li>节能补贴</li>
        <li>医药服务</li>
        <li>流量加油站</li>
        <li>黄金托管</li>
        <li>视频教育订单</li>
        <li>海外房产预约</li>
        <li>我的全球购</li>
        <li>装修服务</li>
      </ul>
      <ul>
        <h5>客户服务</h5>
        <li>返修退换货</li>
        <li>价格保护</li>
        <li>意见建议</li>
        <li>我的问答</li>
        <li>购买咨询</li>
        <li>交易纠纷</li>
        <li>TMesh商城维修</li>
        <li>上门预约服务</li>
        <li>我的发票</li>
        <li>举报中心</li>
      </ul>
    </div>
    <div id="bigRight">
      <div class="myOrder">
          <p>
              收货地址
              <button type="button" class="layui-btn" style="position: relative;left: 889px;" onclick="toAddAddress()">添加地址</button>
          </p>
          
      </div>


      <div class="allBig">
          <table class="layui-hide" id="ID-table-demo-data"></table>
          <script type="text/html" id="operate">
              <div class="layui-clear-space">
                  <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
                  <a class="layui-btn layui-btn-xs" lay-event="delete">删除</a>
              </div>
          </script>
          <script type="text/html" id="default">
              <div class="layui-clear-space">
                  <a class="layui-btn layui-btn-xs" lay-event="default">设为默认</a>
              </div>
          </script>
      </div>

      <!--<div class="buy">
        <div class="buy_top">
          <div>买什么</div>
          <div>查看更多商品专辑</div>
        </div>
        <div style="clear:both;"></div>
        <div class="buy_btm">
          <dl>
            <dt>
              <div>最适合冬季的茶</div>
              <p>不入魔不成仙</p>
            </dt>
            <dd class="ab_goods">
              <div><img src="../member/img/bu.jpg" alt=""></div>
              <div>
                <img src="../member/img/1xb.jpg" alt="">
                <img src="../member/img/1xb1.jpg" alt="">
                <div>32</div>
              </div>
            </dd>
            <div style="clear:both;"></div>
            <dd class="ab_operate">
              <ul>
                <li class="guanzhu"><i class="buy_btm_i1 buy_btm_i"></i>关注 5</li>
                <li class="zhan"><i class="buy_btm_i2 buy_btm_i0"></i>赞 5</li>
                <div style="clear:both;"></div>
              </ul>
            </dd>
          </dl>
          <dl>
            <dt>
              <div>用新奇搞怪献给那些有趣的灵魂</div>
              <p>小太阳骥少</p>
            </dt>
            <dd class="ab_goods">
              <div><img src="../member/img/bu1.jpg" alt=""></div>
              <div>
                <img src="../member/img/2xb.jpg" alt="">
                <img src="../member/img/2xb1.jpg" alt="">
                <div>17</div>
              </div>
            </dd>
            <div style="clear:both;"></div>
            <dd class="ab_operate">
              <ul>
                <li class="guanzhu"><i class="buy_btm_i1 buy_btm_i"></i>关注 5</li>
                <li class="zhan"><i class="buy_btm_i2 buy_btm_i0"></i>赞 5</li>
                <div style="clear:both;"></div>
              </ul>
            </dd>
          </dl>
          <dl>
            <dt>
              <div>流感来了，如何做好防护？</div>
              <p>tmeshmall-tmeshyuan</p>
            </dt>
            <dd class="ab_goods">
              <div><img src="../member/img/bu2.jpg" alt=""></div>
              <div>
                <img src="../member/img/3xb.jpg" alt="">
                <img src="../member/img/3xb1.jpg" alt="">
                <div>23</div>
              </div>
            </dd>
            <div style="clear:both;"></div>
            <dd class="ab_operate">
              <ul>
                <li class="guanzhu"><i class="buy_btm_i1 buy_btm_i"></i>关注 2</li>
                <li class="zhan"><i class="buy_btm_i2 buy_btm_i0"></i>赞 5</li>
                <div style="clear:both;"></div>
              </ul>
            </dd>
          </dl>
          <dl>
            <dt>
              <div>流感来了，如何做好防护？</div>
              <p>tmeshmall-tmeshyuan</p>
            </dt>
            <dd class="ab_goods">
              <div><img src="../member/img/bu3.jpg" alt=""></div>
              <div>
                <img src="../member/img/xb.jpg" alt="">
                <img src="../member/img/xb1.jpg" alt="">
                <div>23</div>
              </div>
            </dd>
            <div style="clear:both;"></div>
            <dd class="ab_operate">
              <ul>
                <li class="guanzhu"><i class="buy_btm_i1 buy_btm_i"></i>关注 4</li>
                <li class="zhan"><i class="buy_btm_i2 buy_btm_i0"></i>赞 11</li>
                <div style="clear:both;"></div>
              </ul>
            </dd>
          </dl>
          <div style="clear:both;"></div>
        </div>
      </div>-->

      <!--<div class="mySwiper">
        <div class="mySwiper_like">
          <div class="left">猜你喜欢</div>
          <ol>
            <li class="liList">1</li>
            <li class="liList">2</li>
            <li class="liList">3</li>
            <div style="clear:both"></div>
          </ol>
          <div style="clear:both"></div>
        </div>
        <ul>
          <li style="display:block;">
            <dl>
              <dt><img src="../member/image/lunbo.jpg" alt=""></dt>
              <dd>
                <div>花王 (Merries) 妙而舒 纸尿裤</div>
                <div>大号 L54片 尿不湿（9-14千克）</div>
                <p>¥83.90</p>
                <span>(已有363668人评价)</span>
              </dd>
            </dl>
            <dl>
              <dt><img src="../member/image/lunbo1.jpg" alt=""></dt>
              <dd>
                <div>三只松鼠 肉干肉脯 休闲零食</div>
                <div>猪肉脯自然片150g/袋子</div>
                <p>¥26.90</p>
                <span>(已有448374人评价)</span>
              </dd>
            </dl>
            <dl>
              <dt><img src="../member/image/lunbo2.jpg" alt=""></dt>
              <dd>
                <div>满减不止5折三只松鼠_小贱牛</div>
                <div>板筋120gx1袋休闲零食特产</div>
                <p>¥22.80</p>
                <span>(已有169149人评价)</span>
              </dd>
            </dl>
            <dl>
              <dt><img src="../member/image/lunbo3.jpg" alt=""></dt>
              <dd>


                <div>良品铺子鸭脖子 甜辣味真空小包装</div>
                <div>香辣卤味零食休闲小吃熟食190g</div>
                <p>¥21.90</p>
                <span>(已有208040人评价)</span>
              </dd>
            </dl>
            <dl>
              <dt><img src="../member/image/lunbo4.jpg" alt=""></dt>
              <dd>
                <div>欧莱雅（LOREAL）男士控油</div>
                <div>（男士洗面奶 收缩毛孔 去黑头）</div>
                <p>¥39.00</p>
                <span>(已有604670人评价)</span>
              </dd>
            </dl>
            <div style="clear:both;"></div>
          </li>
          <li>
            <dl>
              <dt><img src="../member/image/live.jpg" alt=""></dt>
              <dd>
                <div>花王 (Merries) 妙而舒 纸尿裤</div>
                <div>大号 L54片 尿不湿（9-14千克）</div>
                <p>¥83.90</p>
                <span>(已有363668人评价)</span>
              </dd>
            </dl>
            <dl>
              <dt><img src="../member/image/live1.jpg" alt=""></dt>
              <dd>
                <div>三只松鼠 肉干肉脯 休闲零食</div>
                <div>猪肉脯自然片150g/袋子</div>
                <p>¥26.90</p>
                <span>(已有448374人评价)</span>
              </dd>
            </dl>
            <dl>
              <dt><img src="../member/image/live2.jpg" alt=""></dt>
              <dd>
                <div>满减不止5折三只松鼠_小贱牛</div>
                <div>板筋120gx1袋休闲零食特产</div>
                <p>¥22.80</p>
                <span>(已有169149人评价)</span>
              </dd>
            </dl>
            <dl>
              <dt><img src="../member/image/live3.jpg" alt=""></dt>
              <dd>


                <div>良品铺子鸭脖子 甜辣味真空小包装</div>
                <div>香辣卤味零食休闲小吃熟食190g</div>
                <p>¥21.90</p>
                <span>(已有208040人评价)</span>
              </dd>
            </dl>
            <dl>
              <dt><img src="../member/image/live4.jpg" alt=""></dt>
              <dd>
                <div>欧莱雅（LOREAL）男士控油</div>
                <div>（男士洗面奶 收缩毛孔 去黑头）</div>
                <p>¥39.00</p>
                <span>(已有604670人评价)</span>
              </dd>
            </dl>
            <div style="clear:both;"></div>
          </li>
          <li>
            <dl>
              <dt><img src="../member/image/lunbo5.jpg" alt=""></dt>
              <dd>
                <div>花王 (Merries) 妙而舒 纸尿裤</div>
                <div>大号 L54片 尿不湿（9-14千克）</div>
                <p>¥83.90</p>
                <span>(已有363668人评价)</span>
              </dd>
            </dl>
            <dl>
              <dt><img src="../member/image/lunbo6.jpg" alt=""></dt>
              <dd>
                <div>三只松鼠 肉干肉脯 休闲零食</div>
                <div>猪肉脯自然片150g/袋子</div>
                <p>¥26.90</p>
                <span>(已有448374人评价)</span>
              </dd>
            </dl>
            <div style="clear:both;"></div>
          </li>
        </ul>
      </div>-->

      <div id="logo">
        <img src="../member/img/datu.jpg" alt="">
        <img src="../member/img/datu1.jpg" alt="">
      </div>
    </div>
    <div style="clear:both;"></div>
  </div>



  <div class="footer">
    <div class="top">
      <ul>
          <li class="item fore1">
              <i></i>
              品类齐全，轻松购物
          </li>
          <li class="item fore2">
              <i></i>
              多仓直发，极速配送
          </li>
          <li class="item fore3">
              <i></i>
              正品行货，精致服务


          </li>
          <li class="item fore4">
              <i></i>
              天天低价，畅选无忧


          </li>
          <div style="clear:both;"></div>
      </ul>
    </div>
    <div class="wrap">
      <div class="wrap1">
          <div class="wrap2">
             <dl>
                 <dt>购物指南</dt>
                 <dd>购物流程</dd>
                 <dd>会员介绍</dd>
                 <dd>生活旅行/团购</dd>
                 <dd>常见问题</dd>
                 <dd>大家电</dd>
                 <dd>联系客服</dd>
             </dl>
              <dl>
                  <dt>配送方式</dt>
                  <dd>上门自提</dd>
                  <dd>211限时达</dd>
                  <dd>配送服务查询</dd>
                  <dd>配送费收取标准</dd>
                  <dd>海外配送</dd>

              </dl>
              <dl>
                  <dt>支付方式</dt>
                  <dd>货到付款</dd>
                  <dd>在线支付</dd>
                  <dd>分期付款</dd>
                  <dd>邮局汇款</dd>
                  <dd>公司转账</dd>
              </dl>
              <dl>
              <dt>公司转账</dt>
              <dd>售后政策</dd>
              <dd>价格保护</dd>
              <dd>退款说明</dd>
              <dd>返修/退换货</dd>
              <dd>取消订单</dd>


          </dl>
              <dl>
                  <dt>特色服务</dt>
                  <dd>夺宝岛</dd>
                  <dd>DIY装机</dd>
                  <dd>延保服务</dd>
                  <dd>TMesh商城E卡</dd>
                  <dd>TMesh商城通信</dd>
                  <dd>TMesh商城tmeshmall+</dd>
              </dl>
          </div>
      </div>
    </div>
    <p class="p1">
        <a href="/member/#">关于我们</a>
        <a href="/member/#">联系我们</a>
        <a href="/member/#">联系客服</a>
        <a href="/member/#">合作招商</a>
        <a href="/member/#">合作招商</a>
        <a href="/member/#">营销中心</a>
        <a href="/member/#" style="width:80px;">手机TMesh商城</a>
        <a href="/member/#">友情链接</a>
        <a href="/member/#">销售联盟</a>
        <a href="/member/#" style="width:80px;">TMesh商城社区</a>
        <a href="/member/#">风险监测</a>
        <a href="/member/#">隐私政策</a>
        <a href="/member/#" style="width:80px;">TMesh商城公益</a>
        <a href="/member/#" style="width:80px;">English Site</a>
        <a href="/member/#" style="border-right: none">Contact Us</a>
    </p>
    <p class="p2">
        <a href="/member/#">X公网安备 XXXXXXXXXXXXX号</a>
        <a href="/member/#">XICP证XXXXXXX号</a>
        <a href="/member/#">互联网药品信息服务资格证编号(X)-经营性-XXXX-XXXX</a>
        <a href="/member/#">新出发X零 字第大XXXXXX号</a>
    </p>
    <p class="p3">
        <a href="/member/#">互联网出版许可证编号新出网证(X)字XXX号</a>
        <a href="/member/#">出版物经营许可证</a>
        <a href="/member/#">网络文化经营许可证京网文[XXXX]XXXX-XXXX号</a>
        <a href="/member/#">违法和不良信息举报电话：XXXXXXXXX</a>
    </p>
    <p class="p4">
        <a href="/member/#">Copyright © 2004 - 2024  TMesh商城tmesh.cn 版权所有</a>
        <a href="/member/#">消费者维权热线：XXXXXXXXXX</a>
        <a href="/member/#">经营证照</a>
    </p>
    <p class="p5">
        <a href="/member/#">TMesh商城旗下网站：TMesh商城钱包</a>
        <a href="/member/#">TMesh商城云</a>

    </p>
    <p class="img">
        <span class="span icon1"></span>
        <span class="span icon2"></span>
        <span class="span icon3"></span>
        <span class="span icon4"></span>
        <span class="span icon5"></span>
        <span class="span icon6"></span>
    </p>
    <div style="clear: both"></div>
  </div>
  <div class="fixed">
    
    <div class="teSe">
      <ul>
        <li class="test_li1">
          <ol>
            <div></div>
            <li>宽带</li>
            <li>我的旅行订单</li>
            <li>夺宝箱</li>
            <li>我的定期送</li>
            <li>我的竞拍保证金</li>
            <li>TMesh商城白条</li>
            <li>TMesh商城回收</li>
            <li>装机大师</li>
            <li>黄金托管业务</li>
          </ol>
        </li>
        <li class="test_li2"></li>
        <li><a href="/member/#" class="test_li3"></a></li>
      </ul>
    </div>
  </div>

  <form id="create_table_from" lay-filter="create_table_from"  class="layui-form" action="" style="display: none;margin-top: 20px">
      <div class="layui-form-item">
          <label class="layui-form-label" style="width: 70px;margin-left: 2px">姓名</label>
          <div class="layui-input-block">
              <input type="text" name="name" style="margin-left: -10px;width: 190px;" placeholder="请输入姓名" autocomplete="off" class="layui-input">
          </div>
      </div>
      <div class="layui-form-item">
          <div class="layui-inline">
              <label class="layui-form-label" style="width: 80px;margin-left: 5px">手机号</label>
              <div class="layui-input-inline layui-input-wrap">
                  <input type="tel" name="phone" style="margin-left: 15px" placeholder="请填写手机号" lay-verify="required|phone" autocomplete="off" lay-reqtext="请填写手机号" lay-affix="clear" class="layui-input demo-phone">
              </div>
          </div>
      </div>
      <div class="layui-form-item">
          <label class="layui-form-label" style="width: 100px;">所在地区  </label>
          <div class="layui-input-inline">
              <select id="province" name="province" lay-filter="province">
                  <option value="">请选择省</option>
                  <option th:each="address : ${addressList}" th:value="${address.id}" th:text="${address.name}"></option>
              </select>
          </div>
          <div class="layui-input-inline">
              <select id="city" name="city" lay-filter="city">
                  <option value="">请选择市</option>
              </select>
          </div>
          <div class="layui-input-inline">
              <select id="region" name="region" lay-filter="region">
                  <option value="">请选择县/区</option>
              </select>
          </div>
      </div>
      <div class="layui-form-item" style="margin-left: -10px">
          <label class="layui-form-label" style="width: 100px;margin-left: 10px">详细地址</label>
          <div class="layui-input-block">
              <input type="text" name="detailAddress" style="width: 590px;" placeholder="请输入详细地址" autocomplete="off" class="layui-input">
          </div>
      </div>
      <div class="layui-form-item" style="display: none">
          <div class="layui-input-block">
              <button type="submit" id="demo1" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
              <button type="reset" id="demo2" lay-filter="demo2" layui-btn layui-btn-primary>重置</button>
          </div>
      </div>
  </form>
</body>
<script src="../member/js/jquery-3.1.1.min.js"></script>
<script src="../member/js/index.js"></script>
<script src="../member/js/layui-v2.9.14.min.js"></script>
<script src="../member/js/My97DatePicker/WdatePicker.js"></script>

<script th:inline="javascript">
    var memberAddress = [[${memberAddress}]];//获取对象
    console.log("memberAddress: ", memberAddress)
    let province =  "";
    let city =  "";
    let region =  "";
    layui.use(['table','form','layer','jquery'], function(){
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        // 已知数据渲染
        var inst = table.render({
            elem: '#ID-table-demo-data',
            cols: [
                [ //标题栏
                {field: 'name', title: '姓名', width: 80},
                {field: 'phone', title: '手机', width: 140},
                {field: 'area', title: '所在地区', minWidth: 120},
                {field: 'detail', title: '详细地址', minWidth: 140},
                {field: 'operate', title: '操作', width: 120, toolbar: '#operate'},
                {field: 'default', title: '移动设置', width: 120, toolbar: '#default'}
                ]
            ],
            data: memberAddress,
            /*data: [{ // 赋值已知数据
                "name": "10001",
                "phone": "张三1",
                "area": "男",
                "detail": "浙江杭州",
                "province": "",
                "city": "",
                "region": "",
                "LAY_CHECKED": true,
            },{ // 赋值已知数据
                "name": "10001",
                "phone": "张三1",
                "area": "男",
                "detail": "浙江杭州",
                "province": "",
                "city": "",
                "region": ""
            },],*/
            skin: 'grid', // 表格风格
            unresize: false,
            // 菜单被点击的事件
            done: function (res, curr, count) {
                $('th').css({'background-color': '#f3f6f8'});
            }

        });
        
        // 触发单元格工具事件
        table.on('tool(ID-table-demo-data)', function(obj){ // 双击 toolDouble
            var data = obj.data; // 获得当前行数据
            var id = data.id
            province = data.province;
            city = data.city;
            region = data.region;
            if(obj.event === 'edit'){
                var a = $('#demo2');
                a.click()
                $.ajax({
                    type: 'get',
                    url: 'http://member.tmesh.cn/member/memberreceiveaddress/transInfo/'+id,
                    data: JSON.stringify(id),
                    dataType: 'json',
                    contentType:"application/json",
                    success: function (data) {
                        let address = data.address
                        if (data.code == 0) {
                            if (address.province != null && address.province != "") {
                                $.ajax({
                                    type: 'get',
                                    url: 'http://member.tmesh.cn/member/address/addressTree',
                                    data: {parentId:address.province},
                                    dataType: 'json',
                                    success: function (data) {
                                        if (data.code == 0) {
                                            var cityList = data.data;
                                            $("#city").empty();
                                            $("#city").append('<option value="">请选择市</option>');
                                            for (var i = 0; i < cityList.length; i++) {
                                                $("#city").append('<option value="' + cityList[i].id + '">' + cityList[i].name + '</option>');
                                            }
                                            if (address.city != null && address.city != "") {
                                                $.ajax({
                                                    type: 'get',
                                                    url: 'http://member.tmesh.cn/member/address/addressTree',
                                                    data: {parentId:address.city},
                                                    dataType: 'json',
                                                    success: function (data) {
                                                        if (data.code == 0) {
                                                            var regionList = data.data;
                                                            $("#region").empty();
                                                            $("#region").append('<option value="">请选择县/区</option>');
                                                            for (var i = 0; i < regionList.length; i++) {
                                                                $("#region").append('<option value="' + regionList[i].id + '">' + regionList[i].name + '</option>');
                                                            }
                                                        } else {
                                                            layer.msg('设置失败', {icon: 2})
                                                        }
                                                        form.render("select");
                                                        form.val('create_table_from', address);
                                                    },
                                                    error: function (error) {
                                                        console.log(error);
                                                        layer.msg('服务器异常，请联系管理员！！！', {icon: 2})
                                                        layer.close(index);
                                                        form.render("select");
                                                        form.val('create_table_from', address);
                                                    }
                                                });
                                            } else {
                                                form.render("select");
                                                form.val('create_table_from', address);
                                            }
                                        } else {
                                            layer.msg('设置失败', {icon: 2})
                                            form.render("select");
                                            form.val('create_table_from', address);
                                        }
                                    },
                                    error: function (error) {
                                        console.log(error);
                                        layer.msg('服务器异常，请联系管理员！！！', {icon: 2})
                                        layer.close(index);
                                        form.render("select");
                                        form.val('create_table_from', address);
                                    }
                                });
                            } else {
                                form.render("select");
                                form.val('create_table_from', address);
                            }
                            //更改选中值
                            // var province = $("#province option:selected").text();
                            // console.log("province: ", province)
                            // $("#province").val(data.memberReceiveAddress["province"]);
                            // $("#city").val(data.memberReceiveAddress["city"]);
                            // $("#region").val(data.memberReceiveAddress["region"]);
                            //重新渲染下拉框
                            // layui.use('create_table_from', function () {
                            //     var form = layui.form;
                            //     form.render("select");
                            // });
                            layer.open({
                                title: '编辑地址信息',
                                type: 1,
                                area: ['40%','50%'],
                                content: $('#create_table_from'),
                                //按钮
                                btn:['确定','取消'],
                                //确定按钮
                                yes: function(index, layero) {
                                    var isvalid = form.validate('.demo-phone')
                                    if (!isvalid) {
                                        return false;
                                    }
                                    //开启loading
                                    const loading = layer.load(2);

                                    /*
                                    //获取表单内的所有值
                                    form.submit('form-demo-create_table_from', function(data){
                                        var field = data.field; // 获取表单全部字段值
                                        console.log("data: ", data); // 回调函数返回的 data 参数和提交事件中返回的一致
                                        // 执行提交
                                        layer.confirm('确定提交吗？', function(index){
                                            layer.close(index); // 关闭确认提示框
                                            // 显示填写结果，仅作演示用
                                            layer.alert(JSON.stringify(field), {
                                                title: '当前填写的字段值'
                                            });
                                            // 此处可执行 Ajax 等操作
                                            // …
                                        });
                                    });
                                    */

                                    const formData = form.val("create_table_from");
                                    console.log("formData: ", formData);
                                    formData["id"] = id;
                                    formData["province"] = province;
                                    formData["city"] = city;
                                    formData["region"] = region;
                                    console.log("formData: ", formData);
                                    //发送数据到接口
                                    $.ajax({
                                        type: 'post',
                                        url: 'http://member.tmesh.cn/updateMemberAddressInfo.do',
                                        data: JSON.stringify(formData),
                                        dataType: 'json',
                                        contentType:"application/json",
                                        success: function (data) {
                                            if (data.data == true) {
                                                var area = (region != null && region != "") ? province + "\\" + city + "\\" + region
                                                    : (city != null && city != "") ? province + "\\" + city
                                                        : (province != null && province != "") ? province : "";
                                                data["name"] = formData["name"]
                                                data["phone"] = formData["phone"]
                                                data["detail"] = formData["detailAddress"]
                                                data["area"] = area
                                                data["province"] = formData["province"]
                                                data["city"] = formData["city"]
                                                data["region"] = formData["region"]
                                                obj.update({
                                                    name:formData["name"],
                                                    phone:formData["phone"],
                                                    area:area,
                                                    province:formData["province"],
                                                    city:formData["city"],
                                                    region:formData["region"],
                                                })
                                                layer.msg('更新成功', {icon: 1})
                                            } else {
                                                layer.msg('更新失败', {icon: 2})
                                            }
                                            layer.close(index);
                                            layer.close(loading);
                                        },
                                        error: function (error) {
                                            console.log(error);
                                            layer.close(index);
                                            layer.close(loading);
                                            layer.msg('服务器异常，请联系管理员！！！', {icon: 2})
                                        }
                                    });
                                },
                                cancel: function(index, layero){
                                    layer.close(index);
                                },
                                end: function(){
                                    // layer.msg('关闭后的回调', {icon:6});
                                }
                            });
                        } else {
                            layer.msg('服务器异常，请联系管理员！！！', {icon: 2})
                        }
                    },
                    error: function (error) {
                        console.log(error);
                        layer.msg('服务器异常，请联系管理员！！！', {icon: 2})
                        layer.close(index);
                    }
                });

            } else if(obj.event === 'delete'){
                layer.confirm('是否确定删除', {
                    btn: ['确定', '关闭'] //按钮
                }, function(){
                    //发送数据到接口
                    $.ajax({
                        type: 'post',
                        url: 'http://member.tmesh.cn/member/memberreceiveaddress/delete',
                        data: JSON.stringify([id]),
                        dataType: 'json',
                        contentType:"application/json",
                        success: function (data) {
                            if (data.code == 0) {
                                layer.msg('删除成功', {icon: 1})
                                obj.del();
                            } else {
                                layer.msg('删除失败', {icon: 2})
                            }
                        },
                        error: function (error) {
                            console.log(error);
                            layer.msg('服务器异常，请联系管理员！！！', {icon: 2})
                            layer.close(index);
                        }
                    });
                }, function(){
                });
            } else if(obj.event === 'default'){
                //发送数据到接口
                $.ajax({
                    type: 'post',
                    url: 'http://member.tmesh.cn/member/memberreceiveaddress/modfiyDefaultStatus',
                    data: JSON.stringify(id),
                    dataType: 'json',
                    contentType:"application/json",
                    success: function (data) {
                        if (data.code == 0) {
                            layer.msg('设置成功', {icon: 1})
                            table.setRowChecked('ID-table-demo-data', {
                                index: 'all', // 所有行
                                checked: false // 此处若设置 true，则表示全选
                            });
                            table.setRowChecked('ID-table-demo-data', {
                                index: obj.index, // 选中行的下标。 0 表示第一行
                            });
                        } else {
                            layer.msg('设置失败', {icon: 2})
                        }
                    },
                    error: function (error) {
                        console.log(error);
                        layer.msg('服务器异常，请联系管理员！！！', {icon: 2})
                    }
                });

            }
        });

        // // 提交事件
        // form.on('submit(demo1)', function(data){
        //     var field = data.field; // 获取表单字段值
        //     console.log("aaaaaaaaaaaa")
        //     // 显示填写结果，仅作演示用
        //     layer.alert(JSON.stringify(field), {
        //         title: '当前填写的字段值'
        //     });
        //     // 此处可执行 Ajax 等操作
        //     // …
        //     return false; // 阻止默认 form 跳转
        // });

        form.on('select(province)', function(data){
            var elem = data.elem; // 获得 select 原始 DOM 对象
            var text = data.elem[data.elem.selectedIndex].text; // 获得 select 文本值
            var value = data.value; // 获得被选中的值
            var othis = data.othis; // 获得 select 元素被替换后的 jQuery 对象
            province =  text;
            if (value == "") {
                $("#city").empty();
                $("#city").append('<option value="">请选择市</option>');
                $("#region").empty();
                $("#region").append('<option value="">请选择县/区</option>');
                form.render("select");
            } else {
                $.ajax({
                    type: 'get',
                    url: 'http://member.tmesh.cn/member/address/addressTree',
                    data: {parentId:value},
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 0) {
                            var cityList = data.data;
                            $("#city").empty();
                            $("#city").append('<option value="">请选择市</option>');
                            for (var i = 0; i < cityList.length; i++) {
                                $("#city").append('<option value="' + cityList[i].id + '">' + cityList[i].name + '</option>');
                            }
                        } else {
                            layer.msg('设置失败', {icon: 2})
                        }
                        form.render("select");
                    },
                    error: function (error) {
                        console.log(error);
                        layer.msg('服务器异常，请联系管理员！！！', {icon: 2})
                        layer.close(index);
                    }
                });
            }
        });

        form.on('select(city)', function(data){
            var elem = data.elem; // 获得 select 原始 DOM 对象
            var text = data.elem[data.elem.selectedIndex].text; // 获得 select 文本值
            var value = data.value; // 获得被选中的值
            var othis = data.othis; // 获得 select 元素被替换后的 jQuery 对象
            city =  text;

            if (value == "") {
                $("#region").empty();
                $("#region").append('<option value="">请选择县/区</option>');
                form.render("select");
            } else {
                $.ajax({
                    type: 'get',
                    url: 'http://member.tmesh.cn/member/address/addressTree',
                    data: {parentId:value},
                    dataType: 'json',
                    success: function (data) {
                        if (data.code == 0) {
                            var regionList = data.data;
                            $("#region").empty();
                            $("#region").append('<option value="">请选择县/区</option>');
                            for (var i = 0; i < regionList.length; i++) {
                                $("#region").append('<option value="' + regionList[i].id + '">' + regionList[i].name + '</option>');
                            }
                        } else {
                            layer.msg('设置失败', {icon: 2})
                        }
                        form.render("select");
                    },
                    error: function (error) {
                        console.log(error);
                        layer.msg('服务器异常，请联系管理员！！！', {icon: 2})
                        layer.close(index);
                    }
                });
            }
        });

        form.on('select(region)', function(data){
            var elem = data.elem; // 获得 select 原始 DOM 对象
            var text = data.elem[data.elem.selectedIndex].text; // 获得 select 文本值
            var value = data.value; // 获得被选中的值
            var othis = data.othis; // 获得 select 元素被替换后的 jQuery 对象
            region =  text;
            form.render("select");
        });

    });

    function toAddAddress() {
        console.log("toAddAddress")
        province = "";
        city =  "";
        region =  "";
        var form = layui.form;
        var table = layui.table;
        var a = $('#demo2');
        a.click()
        layer.open({
            title: '新增地址信息',
            type: 1,
            area: ['40%','50%'],
            content: $('#create_table_from'),
            //按钮
            btn:['确定','取消'],
            //确定按钮
            yes: function(index, layero) {
                var isvalid = form.validate('.demo-phone')
                console.log("isvalid: ", isvalid)
                if (!isvalid) {
                    return false;
                }
                //开启loading
                const loading = layer.load(2);

                const formData = form.val("create_table_from");
                console.log("formData: ", formData)
                formData["province"] = province
                formData["city"] = city
                formData["region"] = region
                var area = (region != null && region != "") ? province + "\\" + city + "\\" + region
                    : (city != null && city != "") ? province + "\\" + city
                        : (province != null && province != "") ? province : "";
                console.log("formData: ", formData)
                //发送数据到接口
                $.ajax({
                    type: 'post',
                    url: 'http://member.tmesh.cn/saveMemberAddressInfo.do',
                    data: JSON.stringify(formData),
                    dataType: 'json',
                    contentType:"application/json",
                    success: function (data) {
                        if (data.code == 0) {
                            var id = data.data.id;
                            var oldData = table.cache["ID-table-demo-data"];
                            var newRow = {
                                id: id,
                                name: formData["name"],
                                phone: formData["phone"],
                                area: area,
                                detail: formData["detailAddress"],
                                province: province,
                                city: city,
                                region: region,
                                LAY_CHECKED: false,
                            }
                            console.log("newRow: ", newRow)
                            oldData.push(newRow);
                            table.reload('ID-table-demo-data', {
                                data: oldData
                            });
                            layer.msg('新增成功', {icon: 1})
                        } else {
                            layer.msg('新增失败', {icon: 2})
                        }
                        layer.close(index);
                        layer.close(loading);
                    },
                    error: function (error) {
                        console.log(error);
                        layer.close(index);
                        layer.close(loading);
                        layer.msg('服务器异常，请联系管理员！！！', {icon: 2})
                    }
                });
            },
            cancel: function(index, layero){
                layer.close(index);
            },
            end: function(){
                // layer.msg('关闭后的回调', {icon:6});
            }
        });
    }
</script>



</html>
